package base.test6.outputformat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class LogDrive {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1.创建一个 job
        Job job = Job.getInstance(new Configuration());

        //2.指定 job的jar类型
        job.setJarByClass(LogDrive.class);

        //3.指定mapper的方法
        job.setMapperClass(LogMapper.class);

        //4.指定reduce的方法
        job.setReducerClass(LogReducer.class);

        //5.指定输出类型 k2,v2   k4,v4
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        //设置自定义OutputFormat
        job.setOutputFormatClass(LogOutputFormat.class);

        FileInputFormat.setInputPaths(job,new Path("F:\\test\\input"));
        //虽然定义了OutputFormat，但是因为我们OutputFormat继承自fileoutputformat
        //而fileoutputformat要输出一个_SUCCESS文件，所以还需要继续指定一个输出目录
        FileOutputFormat.setOutputPath(job,new Path("F:\\test\\outPut"));

        //5.提交任务job
        boolean b = job.waitForCompletion(true);

        System.exit(b?0:1);
    }
}
